#include<iostream>
#include<pthread.h>
#include<string>
#include<ctime>
    static int num=1;

typedef void(*callback)();
//template<class T>
class thread
{
public:
    thread(callback cb)
    :_name(""),_tid(0),_isrun(false),_start_time(0),_cb(cb)
    {}
    static void* handle(void* args)
    {
        thread* t=static_cast<thread*>(args);
        std::cout<<t->name()<<" "<<t->tid()<<" "<<t->isrun()<<" "<<t->starttime()<<std::endl;
        t->_cb();
        return nullptr;
    }
    // T& gettask(T& callback)
    // {
    //     return _cb();
    // }
    void join()
    {
        pthread_join(_tid,nullptr);
        _isrun=false;
    }
    void run()
    {
        _name="thread"+std::to_string(num++);
        _isrun=true;
        _start_time=time(nullptr);
        pthread_create(&_tid,nullptr,handle,this);
    }
    std::string name()
    {
        return _name;
    }
    pthread_t tid()
    {
        return _tid;
    }
    uint64_t starttime()
    {
        return _start_time;
    }
    bool isrun()
    {
        return _isrun;
    }
    ~thread(){}
private:
    std::string _name;
    pthread_t _tid;
    bool _isrun;
    uint64_t _start_time;
    callback _cb;
};
